package com.telit.firecommand.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.telit.firecommand.entity.CommCameraInfo;
import com.telit.firecommand.entity.FireCamera;
import com.telit.firecommand.vo.SaidaDistrictTreeVO;
import com.telit.firecommand.vo.UavVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * 视频监控DAO
 *
 * @author yuezhuang
 * @date 2022-09-24
 */
@Repository
public interface FireCameraDAO extends BaseMapper<FireCamera> {

//    @Select("<script>"
//            + "SELECT fc.* from comm_camera_info fc "
//            + "INNER JOIN geo_camera_area gca ON fc.camera_index_code = gca.camera_index_code "
//            + "WHERE fc.district_code LIKE concat(#{districtCode},'%') "
//            + "<if test=\"keyWords != null and keyWords != ''\">"
//            + "AND fc.name LIKE concat('%',#{keyWords},'%')"
//            + "</if>"
//            + "AND st_intersects(st_geometry(#{firePoint}), gca.shape) = true "
//            + "</script>")
    
    List<CommCameraInfo> qryCameraListByPoint(@Param("districtCode") String districtCode,
                                              @Param("firePoint") String firePoint,
                                              @Param("keyWords") String keyWords,
                                              @Param("pictureType") Integer pictureType,
                                              @Param("deviceType") String deviceType);

    @Select("<script>"
            + "SELECT id,uav_name,longitude,latitude, is_online, is_flying, uav_code, image_url, equipment_model, equipment_manufacturer "
            + "from comm_uav fc "
            + "WHERE district_code LIKE concat(#{districtCode},'%') "
            + "<if test=\"keyWords != null and keyWords != ''\">"
            + "AND uav_name LIKE concat('%',#{keyWords},'%')"
            + "</if>"
            + "AND st_distance(st_geometry('point ('||longitude||' '||latitude||')'),\n"
            + "      st_geometry('point(${longitude} ${latitude})'))*111.1949 <![CDATA[<= ]]> #{distance}::numeric"
            + "</script>")
    List<UavVO> qryUavListByPoint(@Param("districtCode") String districtCode,
                                  @Param("longitude") String longitude,
                                  @Param("latitude") String latitude,
                                  @Param("distance") String distance,
                                  @Param("keyWords") String keyWords);

    List<SaidaDistrictTreeVO> areaTree(@Param("areaCode") String areaCode,
                                       @Param("type") String type,
                                       @Param("online") String online,
                                       @Param("cameraName") String cameraName);

}
